package v1

import (
	"github.com/gin-gonic/gin"
	"guns-go/model/request"
	"guns-go/model/response"
	"guns-go/service"
)

// @Tags DictData
// @Summary 分页获取字典数据列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictDataParam true "搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictData/page [get]
func SysDictDataPage(c *gin.Context) {

	var D request.SysDictDataParam
	_ = c.ShouldBindQuery(&D)

	err, DictDataResult := service.SysDictDataPage(&D, c)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(DictDataResult, c)
}

// @Tags DictData
// @Summary 新增字典数据
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictDataParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictData/add [post]
func SysDictDataAdd(c *gin.Context) {

	var D request.SysDictDataParam
	_ = c.ShouldBindJSON(&D)

	err := service.SysDictDataAdd(&D)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags DictData
// @Summary 修改字典数据
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictDataParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictData/edit [post]
func SysDictDataEdit(c *gin.Context) {

	var D request.SysDictDataParam
	_ = c.ShouldBindJSON(&D)

	err := service.SysDictDataEdit(&D)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags DictData
// @Summary 删除字典数据
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictDataParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictData/delete [post]
func SysDictDataDelete(c *gin.Context) {

	var D request.SysDictDataParam
	_ = c.ShouldBindJSON(&D)

	err := service.SysDictDataDelete(&D)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
